/*
package org.linlinjava.litemall.wx.annotation.support;


import com.aliyuncs.utils.HttpsUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.linlinjava.litemall.wx.annotation.Ide;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

*
 * 接口幂等性的 -- 分布式锁实现


@Aspect
@Component
public class ReqSubmitAspect {

    @Autowired
    private RedisTemplate redisTemplate;

    @Pointcut("@annotation(org.linlinjava.litemall.wx.annotation.Ide)")
    public void idePointCut() {
    }

    @Around("idePointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        // 使用分布式锁 机制-实现
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();

        Ide ide = method.getAnnotation(Ide.class);
        int lockSeconds = ide.lockTime();
        HttpServletRequest request = HttpServlet.getRequest();
//        String token =tokenService.getToken(request);
//        if(token.isEmpty()){
//            return joinPoint.proceed();
//        }
        String requestURI = request.getRequestURI();
        String key = getIdeKey(request.getRemoteHost() + requestURI, requestURI);
        String clientId = UUID.randomUUID().toString();
        Boolean lock = redisTemplate.opsForValue().setIfAbsent("" + request.getRemoteHost() + requestURI, clientId, lockSeconds, TimeUnit.SECONDS);
        if (lock) {
            // 获取锁成功
            Object result;
            try {
                // 执行进程
                result = joinPoint.proceed();
            } finally {
                // 解锁
                redisTemplate.delete(key);
            }
            return result;
        } else {
            // 获取锁失败，认为是重复提交的请求
            System.out.println("重复提交");
            throw new Exception("重复请求，请稍后再试!");
        }
    }

    private String getIdeKey(String token, String requestURI) {
        return token + requestURI;
    }
}
*/
